module(..., package.seeall)

ActMag = {}
ActMag_mt ={__metatable = {}, __index = ActMag}

function new(params)
	local obj = {dict={}}
	setmetatable(obj, ActMag_mt)
	return obj
end

DEFAULT=new()

function ActMag:Reset()
	self.dict={}
end

function ActMag:GetActFun(key)
	return self.dict[key]
end

function ActMag:RegActFun(key,act)
	if not act then return nil,'bad args for fun' end
	if self:GetActFun(key) then return nil,'key has exist' end
	self.dict[key]=act
	return true
end

function ActMag:RequireActFun(key)
	local fun=self:GetActFun(key)
	if fun then return fun end
	local modid,group,fname=string.match(key,"^([^.:]*).?([^:]*):(.+)$")
	assert(modid and fname,'bad act key '..tostring(key))
	local r,m=pcall(require,string.gsub(modid,"/", "."))
	if not r then return r,m end
	local fun
	if #group>0 then
		fun= m[group][fname]
	else
		fun=m[fname]
	end
	if fun then self:RegActFun(key,fun) end
	return fun
end

